package com.tjsinfo.tjsoa.system.dao;

import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.tjsinfo.tjsoa.system.vo.TSystemBeiWang;

public class TSystemBeiWangDao extends HibernateDaoSupport implements ITSystemBeiWangDao{

	private static final Log log = LogFactory
	.getLog(TSystemDepartmentDao.class);

	protected void initDao() {
	}
	public void save(TSystemBeiWang systemBeiWang) {
		log.debug("save systemBeiWang");
		try {
			getHibernateTemplate().save(systemBeiWang);
			log.debug("save systemBeiWang success");
		} catch (RuntimeException e) {
			log.debug("save systemBeiWang fail");
			throw e;
		}
	}
	public List queryAll(Integer userId) {
		String sql = "from TSystemBeiWang where userId = "+userId;
		
		return getHibernateTemplate().find(sql);
	}
	public void update(String date, String message,String id) {
		String sql = "update TSystemBeiWang as t set t.datetime='"+date+"' , " +"t.message='"+message+"' where id="+id;
		System.out.println(sql);
		Session session = getHibernateTemplate().getSessionFactory().openSession();
		Query query = session.createQuery(sql);
		session.beginTransaction();
		query.executeUpdate();
		session.getTransaction().commit();
        session.flush();
        session.close();
	}

}
